﻿@model LeadMaster.ViewModels.ViewModelSchedules

@using (Html.BeginForm("AddSection", "Schedules", FormMethod.Post, new { id="formaddsection" }))
{
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>Select a library section from the dropdown, or enter details for a new section</legend>
        @Html.HiddenFor(m => m.ScheduleTemplateID)
        @Html.HiddenFor(m => m.ScheduleSection.ScheduleSectionsID)

        @Html.DropDownListFor(model => model.ScheduleSectionID, new SelectList(Model.ScheduleSections, "ScheduleSectionsID", "FieldHeader"), "Do not want to use a library section, but will enter my own details")
        <hr />
        <div class="editor-label">
            @Html.Label("Section Heading")
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.ScheduleSection.FieldHeader, new { @class = "largetextbox" })
            @Html.ValidationMessageFor(model => model.ScheduleSection.FieldHeader)
        </div>
        <div class="spacer"></div>
        <div class="editor-label">
            @Html.LabelFor(model => model.ScheduleSection.Content)
        </div>
        <div class="editor-field">
            @Html.TextAreaFor(model => model.ScheduleSection.Content, new { @class = "notes" })
            @Html.ValidationMessageFor(model => model.ScheduleSection.Content)
        </div>
        <div class="spacer"></div>
        <div class="spacer"></div>
    </fieldset>
}


<script type="text/javascript">
    $(document).ready(function () {

        $('#formaddsection').submit(function () {
            if ($('#ScheduleSectionID').val() == 0 &&
            ($('#ScheduleSection_FieldHeader').val().toString().length == 0 ||
            $('#ScheduleSection_Content').val().toString().length == 0)
            ) {
                alert("Please select either a pre-saved section or enter details");
                return false;
            }
            return true;
        });

    });
</script>
